<?php
namespace app\api\controller;
use app\user\controller\User;
use think\Db;
class Chumo extends Authinfo
{
	public function wozijin(){
		$sfid=input('sfid');
		if($sfid){
			$info['wozijin']=Db::name('Zijininfo')->where('sfid',$sfid)->field('price')->sum('price');
			$minfos=Db::name('Zijininfo')->where('sfid',$sfid)->field('id,zmid,year,zhen,cun,price,fftime,month,catid')->order('fftime DESC')->select();
			if($minfos){
				foreach ($minfos as $key => $value) {
					$minfos[$key]['zmidtitle']=get_zijinmingcheng($value['zmid']);
					$minfos[$key]['times']=time_yueri($value['fftime']);
					$minfos[$key]['catname']=get_zjcat($value['catid']);
				}

				$info['zijinlist']=$minfos;
			}
			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=10003;
		}

		return json($data);

	}
	public function wozijinnerong(){
		$id=input('id');
		if($id){
			$info=Db::name('Zijinmanage')->where('id',$id)->find();
			if($info){
				$info['catname']=get_zjcat($info['catid']);
				$info['zhengce']=get_zcyw($info['zcid']);
			}
			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=10003;
		}
		return json($data);

	}

	public function bencun(){

		$zmid=input('zmid');
		$cun=input('cun');
		if($cun&&$zmid){

			$maps[]=array('cun','like',$cun.'%');
			$maps[]=array('zmid','=',$zmid);
			$info=Db::name('Zijininfo')->where($maps)->field('id,name,price,fftime,zhen,cun,zu,sfid,sex')->order('id DESC')->select();

			if($info){
				foreach ($info as $key => $value) {
					$info[$key]['time']=time_nianyueri($value['fftime']);
					if(strlen($value['sfid'])==15){
						$info[$key]['sfid']=substr_replace($value['sfid'],"****",8,4);
					}else{
						$info[$key]['sfid']=substr_replace($value['sfid'],"****",10,4);
					}
				}
			}

		}
		if($info){
			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=50005; //无补贴内容l ！
		}
		return json($data);

	}
	public function dwopenlist(){
		$townsid=input('townsid');
		if($townsid){
			$info=Db::name('Jcopen')->where(['townsid'=>$townsid,'catid'=>1])->field('title,create_time,id,townsid')->order('id DESC')->select();
			if($info){
				foreach ($info as $key => $value) {
					$info[$key]['towns']=get_towns($value['townsid']);
					$info[$key]['time']=time_nianyueri($value['create_time']);
				}
				$data['status']=1;
				$data['info']=$info;
			}else{

			}
		}else{
			$data['status']=60005; //无补贴内容l ！
		}
		return json($data);
	}

	public function dwopenview(){
		$id=input('id');
		if($id){
			$info=Db::name('Jcopen')->where('id',$id)->find();
			$ids=Db::name('Jcopen')->where('id',$id)->setInc('nums');
			if($info){
				$info['towns']=get_alltowns($info['townsid']);
				$info['time']=time_nianyueri($info['create_time']);
				$info['nickname']=get_nickname($info['uid']);
				//$info['content']=str_replace(array('/public/static/uploads/editor/'),array('http://sanqingjw.gov.cn/public/static/uploads/editor/'),$info['content']);
			}
		}
		if($info){
			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=60005; //无补贴内容l ！
		}
		return json($data);

	}
	public function cwopenlist(){
		$townsid=input('townsid');
		if($townsid){
			$info=Db::name('Jcopen')->where(['townsid'=>$townsid,'catid'=>2])->field('title,create_time,id,townsid')->order('id DESC')->select();
			if($info){
				foreach ($info as $key => $value) {
					$info[$key]['towns']=get_towns($value['townsid']);
					$info[$key]['time']=time_nianyueri($value['create_time']);
				}
				$data['status']=1;
				$data['info']=$info;
			}else{

			}
		}else{
			$data['status']=60005; //无补贴内容l ！
		}
		return json($data);
	}

	public function cwopenview(){
		$id=input('id');
		if($id){
			$info=Db::name('Jcopen')->where('id',$id)->find();
			$ids=Db::name('Jcopen')->where('id',$id)->setInc('nums');
			if($info){
				$info['towns']=get_alltowns($info['townsid']);
				$info['time']=time_nianyueri($info['create_time']);
				$info['nickname']=get_nickname($info['uid']);
				//$info['content']=str_replace(array('/public/static/uploads/editor/'),array('http://sanqingjw.gov.cn/public/static/uploads/editor/'),$info['content']);
			}
		}
		if($info){
			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=60005; //无补贴内容l ！
		}
		return json($data);
	}
	public function cunother(){
		$townsid=input('townsid');
		if($townsid){
			$tname=get_towns($townsid);
			if($tname){
				$tnames=mb_substr($tname,0,2,'utf-8');
				$map=array();
				$maps[]=array('cun','like',$tnames.'%');
				$info=Db::name('Zijininfo')->distinct(true)->where($maps)->field('zmid,fftime')->order('fftime DESC')->select();
				foreach ($info as $key => $value) {
					$zmids[]=$value['zmid'];

				}
				$mapss=array();
				$mapss[]=array('id','in',implode(',', $zmids));
				$infos=Db::name('zijinmanage')->where($mapss)->field('title,create_time,id')->order('id DESC')->select();
				foreach ($infos as $key1 => $value1) {
					$infos[$key1]['times']=time_yueri($value1['create_time']);
					$infos[$key1]['tname']=$tnames;
				}

			}
			if($infos){
				$datas['status']=1;
				$datas['info']=$infos;
			}else{
				$datas['status']=0;
				$datas['info']='没有数据';
			}
		}else{
			$datas['status']=0;
			$datas['info']='参数缺少';
		}
		return json($datas);
	}
	public function caiwushouzhi(){
		$townsid=input('townsid');
		if($townsid){
			$map=array();
			$map[]=array('townsid','=',$townsid);
			$info=Db::name('Proof')->where($map)->order('create_time DESC')->select();

			if($info){
				$infozc=Db::name('Proof')->where($map)->sum('creditamount');
				$infosr=Db::name('Proof')->where($map)->sum('debitamount');
				foreach ($info as $key => $value) {

					if($value['creditamount']==0){
						$info[$key]['mingzi']='收入';
						$info[$key]['zijin']=$value['debitamount'];
					}else{
						$info[$key]['mingzi']='支出';
						$info[$key]['zijin']=$value['creditamount'];
					}
					$info[$key]['time']=time_nianyueri($value['create_time']);
				}
			}
		}
		if($info){
			$data['status']=1;
			$data['info']=$info;
			$data['zc']=$infozc;
			$data['sr']=$infosr;
		}else{
			$data['status']=50005; //无补贴内容l ！
		}
		return json($data);
	}
	public function zcywlist(){

		$info=Db::name('Huimin')->field('id,title,cwtime,catid')->order('id DESC')->select();
		if($info){
			foreach ($info as $key => $value) {
				$info[$key]['catname']=get_catname($value['catid']);
				$info[$key]['time']=time_nianyueri($value['cwtime']);

			}
			$data['status']=1;
			$data['info']=$info;

		}else{
			$data['status']=10092;
		}

		return json($data);

	}


	public function zcywview(){

		$id=input('id');
		if($id){
			$info=Db::name('Huimin')->where('id',$id)->find();
			$ids=Db::name('Huimin')->where('id',$id)->setInc('nums');
		}

		if($info){
			$info['catname']=get_catname($info['catid']);
			$info['time']=time_nianyueri($info['cwtime']);


			$data['status']=1;
			$data['info']=$info;
		}else{
			$data['status']=10092;
		}

		return json($data);
	}

	public function pinkuhuinfo(){
		$townsid=input('townsid');
		if($townsid){
			$cun=mb_substr(get_towns($townsid),0,2,'utf-8');
			$map=array();
			$map[]=array('cun','like',$cun.'%');
			$info=Db::name('Pinkuhu')->where($map)->order('shouru DESC')->select();
		}
		if($info){
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0;
			$datas['info']='';
		}
		return json($datas);

	}
	public function zichaninfo(){
		$map=array();
		$townsid=input('townsid');
		$map[]=array('zctype','in','大型机器,经营性机器设备,非经营性房屋及建筑物,非经营性办公设备,农田水利设施,道路,桥梁,其它公益设施,其他,在建工程,固定资产,农业资产,机械,建筑类,机械类,办公');
		$map[]=array('townsid','=',$townsid);
		$info=Db::name('Zichanziyuan')->where($map)->select();
		if($info){
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0;
			$datas['info']='无信息！';
		}
		return json($datas);
	}
	public function ziyuaninfo(){
		$map=array();
		$townsid=input('townsid');
		$map[]=array('zctype','in','水田,林木资产,荒地,场地,资源');
		$map[]=array('townsid','=',$townsid);
		$info=Db::name('Zichanziyuan')->where($map)->select();
		if($info){
			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0;
			$datas['info']='无信息！';
		}
		return json($datas);
	}

}
